package com.sky.controller.user;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "小程序套餐相关接口")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @GetMapping("/list")
    @ApiOperation("根据分类id查询套餐")                                           //unless 满足条件则不进行缓存
    @Cacheable(value = "setmealCache",key = "'setmeal_'+#categoryId",unless = "#result.data == null || #result.data.size()<1")
    public Result list(Long categoryId){
       List<Setmeal>  setmeal = setmealService.list(categoryId);
        return Result.success(setmeal);
    }

    @GetMapping("/dish/{id}")
    @ApiOperation("根据id查询套餐")
    public Result getByid(@PathVariable Long id){
        List<DishItemVO> setmeal = setmealService.setmealList(id);
        return Result.success(setmeal);
    }

}
